<?php
class client_user {
	var $id=false;
	var $user_name=false;
	var $nick_name=false;
	var $vip=false;
	var $ip=false;
	var $get_YB=false;
	var $last_login=false;
	var $RP=false;
	var $ques_count=false;
	var $login=false;
	
	function user_init(){
		$nick_name=$this->nick_name;
		$sql="select * from user_info where nick_name='$nick_name' ";
		$res=run_sql($sql,__LINE__);
		if(!$row=mysql_fetch_row($res)) {
			//未找到该用户，初始化
			$this->new_user();			
		}
		$this->get_user_info();
		return;
	}
	function new_user(){
		$user_name=$this->user_name;
		$nick_name=$this->nick_name;
		$ip=get_ip();
		$last_login=get_date_time();
		$sql="insert into user_info (user_name,nick_name,ip,last_login) values ('$user_name','$nick_name','$ip','$last_login')";
		run_sql($sql,__LINE__);
		return;
	}
	//从数据库获取用户信息
	function get_user_info(){
		$nick_name=$this->nick_name;
		$sql="select * from user_info where nick_name='$nick_name' ";
		$res=run_sql($sql,__LINE__);
		if(!$row=mysql_fetch_array($res)) {
			die('error: no user');
		}else {
			$this->get_YB=$row['get_YB'];
			$this->ip=$row['ip'];
			$this->last_login=$row['last_login'];
			$this->nick_name=$row['nick_name'];
			$this->RP=$row['RP'];
			$this->id=$row['id'];
			$this->ques_count=$row['ques_count'];
			if(!isset($_COOKIE['client_login_flag'])) {
				$this->update_login();
			}
			setcookie('client_login_flag','yes',0,'/');
		}
	}
	//更新登录
	function update_login() {
		$ip=get_ip();
		$last_login=get_date_time();
		$id=$this->id;
		$sql="update user_info set ip='$ip' , last_login='$last_login' where id=$id";
		run_sql($sql,__LINE__);
	}
	//设置用户数据库信息
	function set_user_info() {
		
	}
	function get_ques_count() {
		if($this->nick_name) {
			$nick_name=$this->nick_name;
			global $dbh;
			$sql="select count(*) from ";
		}else die('not login!');
		return;
	}
}
?>